package com.cq.hd.admin.controller;

import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.system.api.TbContentCategoryApi;
import com.cq.hd.system.api.dto.ContentCategoryPageDto;
import com.cq.hd.system.api.dto.ContentCategorySaveDto;
import com.cq.hd.system.api.dto.ContentCategoryUpdateDto;
import com.cq.hd.system.api.vo.ContentCategoryPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "学院分类相关接口")
@Slf4j
@RestController
@RequestMapping("/contentCategory")
public class TbContentCategoryController extends BaseController {

    private TbContentCategoryApi contentCategoryApi;

    @Autowired
    public void setContentCategoryApi(TbContentCategoryApi contentCategoryApi) {
        this.contentCategoryApi = contentCategoryApi;
    }

    @ApiOperation(value = "学院分类列表")
    @ApiImplicitParam(name = "contentCategoryPageDto", value = "学院分类查询参数", paramType = "query", dataType = "ContentCategoryPageDto")
    @ApiResponse(response = ContentCategoryPageVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("content:category:list")
    @RequiresPermissionsDesc(menu = {"火火学院管理", "内容分类"}, button = "查询")
    @GetMapping("/page")
    public Result<Page<ContentCategoryPageVo>> pageContentCategory(ContentCategoryPageDto contentCategoryPageDto) {
        contentCategoryPageDto.setOrderType(1);
        return contentCategoryApi.pageContentCategory(contentCategoryPageDto);
    }

    @ApiOperation(value = "保存学院分类")
    @ApiImplicitParam(name = "contentCategorySaveDto", value = "学院分类保存参数", paramType = "body", dataType = "ContentCategorySaveDto")
    @RequiresPermissions("content:category:save")
    @RequiresPermissionsDesc(menu = {"火火学院管理", "内容分类"}, button = "保存")
    @PostMapping("/save")
    public Result<Object> saveContentCategory(@Validated @RequestBody ContentCategorySaveDto contentCategorySaveDto) {
        return contentCategoryApi.saveContentCategory(contentCategorySaveDto);
    }

    @ApiOperation(value = "更新学院分类")
    @ApiImplicitParam(name = "contentCategoryUpdateDto", value = "学院分类更新参数", paramType = "body", dataType = "ContentCategoryUpdateDto")
    @RequiresPermissions("content:category:update")
    @RequiresPermissionsDesc(menu = {"火火学院管理", "内容分类"}, button = "更新")
    @PostMapping("/update")
    public Result<Boolean> updateContentCategory(@Validated @RequestBody ContentCategoryUpdateDto contentCategoryUpdateDto) {
        return contentCategoryApi.updateContentCategory(contentCategoryUpdateDto);
    }

    @ApiOperation(value = "删除学院分类")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    @RequiresPermissions("content:category:delete")
    @RequiresPermissionsDesc(menu = {"火火学院管理", "内容分类"}, button = "删除")
    @PostMapping("/delete")
    public Result<Boolean> deleteContentCategory(Long id) {
        return contentCategoryApi.deleteContentCategory(id);
    }
}
